package com.mocha.auth.handler;

import com.coffee.core.CoffeeResponse;
import com.coffee.security.CoffeeUser;
import com.coffee.security.CoffeeUserBO;
import com.mocha.bss.loginout.api.RegenaUserFeignService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author songkui
 * @since 2025/5/15
 */
@Service
@AllArgsConstructor
@Slf4j
public class UserDetailsLoadHandler implements CoffeeUserDetailsLoadHandler {

    private final RegenaUserFeignService userFeignService;

    @Override
    public CoffeeUser handle(CoffeeUserBO coffeeUserBO) {
//        String json = "{\"permissions\":[\"sys_role_export\",\"sys_dept_del\",\"job_sys_job_add\",\"job_sys_job_export\",\"sys_user_edit\",\"sys_file_del\",\"sys_menu_del\",\"sys_role_edit\",\"codegen_template_edit\",\"sys_token_del\",\"sys_dept_add\",\"sys_role_del\",\"sys_syspublicparam_del\",\"job_sys_job_refresh_job\",\"sys_dict_del\",\"sys_syspublicparam_edit\",\"sys_syspublicparam_add\",\"sys_user_del\",\"sys_menu_add\",\"codegen_template_add\",\"sys_client_add\",\"sys_dept_edit\",\"sys_menu_edit\",\"sys_post_export\",\"codegen_template_export\",\"sys_user_add\",\"sys_user_export\",\"job_sys_job_del\",\"sys_log_del\",\"codegen_template_del\",\"sys_client_del\",\"sys_client_edit\",\"codegen_group_export\",\"job_sys_job_run_job\",\"job_sys_job_start_job\",\"sys_post_view\",\"sys_dict_edit\",\"job_sys_job_edit\",\"codegen_group_view\",\"sys_log_export\",\"codegen_group_del\",\"sys_post_add\",\"job_sys_job_shutdown_job\",\"sys_dict_add\",\"codegen_template_view\",\"sys_role_add\",\"codegen_group_edit\",\"sys_post_del\",\"sys_role_perm\",\"sys_post_edit\",\"codegen_group_add\"],\"roles\":[1],\"sysUser\":{\"deptId\":4,\"updateTime\":\"2023-07-07T14:55:40\",\"avatar\":\"/admin/sys-file/s3demo/7ff4ca6b7bf446f3a5a13ac016dc21af.png\",\"delFlag\":\"0\",\"userId\":1,\"giteeLogin\":\"log4j\",\"lockFlag\":\"0\",\"createBy\":\" \",\"miniOpenid\":\"oBxPy5E-v82xWGsfzZVzkD3wEX64\",\"password\":\"$2a$10$c/Ae0pRjJtMZg3BnvVpO.eIK6WYWVbKTzqgdy3afR7w.vd.xi3Mgy\",\"createTime\":\"2018-04-20T07:15:18\",\"phone\":\"17034642999\",\"updateBy\":\"admin\",\"name\":\"管理员\",\"nickname\":\"管理员\",\"email\":\"pig4cloud@qq.com\",\"username\":\"admin\"}}";
//       String json = """
//               {"deptId":4,"id":1,"idpType":"wx","lockedFlag":true,"mobile":"17034642999","nickname":"管理员","password":"$2a$10$c/Ae0pRjJtMZg3BnvVpO.eIK6WYWVbKTzqgdy3afR7w.vd.xi3Mgy","permissions":["sys_role_export","sys_dept_del","job_sys_job_add","job_sys_job_export","sys_user_edit","sys_file_del","sys_menu_del","sys_role_edit","codegen_template_edit","sys_token_del","sys_dept_add","sys_role_del","sys_syspublicparam_del","job_sys_job_refresh_job","sys_dict_del","sys_syspublicparam_edit","sys_syspublicparam_add","sys_user_del","sys_menu_add","codegen_template_add","sys_client_add","sys_dept_edit","sys_menu_edit","sys_post_export","codegen_template_export","sys_user_add","sys_user_export","job_sys_job_del","sys_log_del","codegen_template_del","sys_client_del","sys_client_edit","codegen_group_export","job_sys_job_run_job","job_sys_job_start_job","sys_post_view","sys_dict_edit","job_sys_job_edit","codegen_group_view","sys_log_export","codegen_group_del","sys_post_add","job_sys_job_shutdown_job","sys_dict_add","codegen_template_view","sys_role_add","codegen_group_edit","sys_post_del","sys_role_perm","sys_post_edit","codegen_group_add"],"roleIds":[1],"username":"admin"}
//                """;
//        CoffeeUser user = JSONUtils.parse(json, CoffeeUser.class);
        CoffeeResponse<CoffeeUser> response = userFeignService.login(coffeeUserBO);
        return response.getData();
    }
}
